<template>
    <div>
        <van-nav-bar title="标题" left-text="返回" left-arrow @click-left="onClickLeft" />
        <van-button type="primary" @click="order(yYinfo._id,yYinfo.nickname)">预约</van-button>
    </div>
</template>

<script setup lang="ts">
import 'vant/es/Dialog/style';
import 'vant/es/toast/style';
import { Dialog, Toast } from 'vant'
import axios from "axios";
import { ref } from 'vue';

const onClickLeft = () => {
    history.back()
}

const userinfo = JSON.parse(sessionStorage.getItem('user_data'))
console.log(userinfo);

const yYinfo = ref()

if (userinfo == null) {
    Toast.fail('未登录，请先登录！亲');
} else {
    yYinfo.value = userinfo.data.info
}

const order = (id: string,nickname:string) => {

    console.log(id,nickname)

    Dialog.confirm({
        title: '标题',
        message:
            '确定预约吗？',
    })
        .then(() => {
            Toast.success('预约成功！');

            axios.post('/api/users/yY', {
                id, nickname
            }).then(res => {
                console.log(res);
            })

        })
        .catch((e) => {
            // on cancel
            Toast.fail('预约失败！' + e);
        });
}

</script>

<style scoped>

</style>